var lang={};
lang.original="en";
lang.translate="es";

function getById(id)
{
	return document.getElementById(id);
}
function appSetup()
{
	var actual=getById("actual-lang");
	var text=getById("text");
	var en2es=getById("en2es");
	var button=getById("translate-button");
	var spinner=getById("spinner");
	button.addEventListener("click",function(){
		spinner.style.visibility="visible";
		require(["translate"],function(translate){
					translate.translate(lang.original,lang.translate,text.value);
		});
	});
	en2es.addEventListener("click",function(){
		lang.original="en";
		lang.translate="es";
		document.location.href="#content";
		actual.textContent="English to Spanish";
	});
	var es2en=getById("es2en");
	es2en.addEventListener("click",function(){
		lang.original="es";
		lang.translate="en";
		document.location.href="#content";
		actual.textContent="Spanish to English";
	});
	var fr2es=getById("fr2es");
	fr2es.addEventListener("click",function(){
		lang.original="fr";
		lang.translate="es";
		document.location.href="#content";
		actual.textContent="French to Spanish";
	});
	var es2fr=getById("es2fr");
	es2fr.addEventListener("click",function(){
		lang.original="es";
		lang.translate="fr";
		document.location.href="#content";
		actual.textContent="Spanish to French";
	});
	spinner.style.visibility="hidden";
	


}
if(navigator.mozSetMessageHandler!=undefined)
{
	navigator.mozSetMessageHandler('activity', function(activityRequest) {
	  var option = activityRequest.source;

	  if(option.name === "translate"){
		getById("text").value=option.data;
	  }
	});
}
appSetup();
